﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Golf.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace Golf.DAL
{
    /// <summary>
    /// 数据访问类:Golf_Order
    /// </summary>
    public partial class Golf_Order : IGolf_Order
    {
        public Golf_Order()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("Id", "Golf_Order");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            int result = DbHelperSQL.RunProcedure("Golf_Order_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  增加一条数据
        /// </summary>
        public int Add(Golf.Model.Golf_Order model)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@OrderNumber", SqlDbType.NVarChar,15),
					new SqlParameter("@OrderSumPrice", SqlDbType.Decimal,9),
					new SqlParameter("@UserId", SqlDbType.Int,4),
					new SqlParameter("@FristName", SqlDbType.NVarChar,100),
					new SqlParameter("@LastName", SqlDbType.NVarChar,100),
					new SqlParameter("@ProductSumPrice", SqlDbType.Decimal,9),
					new SqlParameter("@TransportationPrice", SqlDbType.Decimal,9),
					new SqlParameter("@MailTypeId", SqlDbType.Int,4),
					new SqlParameter("@IsCoupon", SqlDbType.Bit,1),
					new SqlParameter("@CouponPrice", SqlDbType.Decimal,9),
					new SqlParameter("@IsAddPrice", SqlDbType.Int,4),
					new SqlParameter("@AddPriceState", SqlDbType.NVarChar,200),
					new SqlParameter("@AddPrice", SqlDbType.Decimal,9),
					new SqlParameter("@ProductNumberList", SqlDbType.NVarChar,2000),
					new SqlParameter("@OrderGeneratedTime", SqlDbType.DateTime),
					new SqlParameter("@OrderVerifyTime", SqlDbType.DateTime),
					new SqlParameter("@VerifyNameId", SqlDbType.Int,4),
					new SqlParameter("@AddressId", SqlDbType.Int,4),
					new SqlParameter("@UserMessage", SqlDbType.NVarChar,500),
					new SqlParameter("@UserIp", SqlDbType.NVarChar,15),
					new SqlParameter("@IsPayment", SqlDbType.Int,4),
					new SqlParameter("@PaymentTypeId", SqlDbType.Int,4),
					new SqlParameter("@PaymentBankId", SqlDbType.Int,4),
					new SqlParameter("@PaymentPrice", SqlDbType.Decimal,9),
					new SqlParameter("@PaymentTime", SqlDbType.DateTime),
					new SqlParameter("@PaymentOrderNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@RefundTypeId", SqlDbType.Int,4),
					new SqlParameter("@LogisticsStateId", SqlDbType.Int,4),
					new SqlParameter("@Logisticsnumber", SqlDbType.NVarChar,50),
					new SqlParameter("@PenskeLogistics", SqlDbType.NVarChar,50),
					new SqlParameter("@LogisticsRemarks", SqlDbType.NVarChar,200),
					new SqlParameter("@OrderStateCodeId", SqlDbType.Int,4),
					new SqlParameter("@ProductOrderNumber", SqlDbType.Int,4),
					new SqlParameter("@IsDeliver", SqlDbType.Bit,1),
					new SqlParameter("@DeliverTime", SqlDbType.DateTime),
					new SqlParameter("@DeliverUnitId", SqlDbType.Int,4),
					new SqlParameter("@IsPrintDeliver", SqlDbType.Bit,1),
					new SqlParameter("@AllocateUnitId", SqlDbType.Int,4),
					new SqlParameter("@AllocateTime", SqlDbType.DateTime),
					new SqlParameter("@AdminMessageId", SqlDbType.Int,4),
					new SqlParameter("@IsShow", SqlDbType.Bit,1),
					new SqlParameter("@Pro_AttrList", SqlDbType.NVarChar,2000)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.OrderNumber;
            parameters[2].Value = model.OrderSumPrice;
            parameters[3].Value = model.UserId;
            parameters[4].Value = model.FristName;
            parameters[5].Value = model.LastName;
            parameters[6].Value = model.ProductSumPrice;
            parameters[7].Value = model.TransportationPrice;
            parameters[8].Value = model.MailTypeId;
            parameters[9].Value = model.IsCoupon;
            parameters[10].Value = model.CouponPrice;
            parameters[11].Value = model.IsAddPrice;
            parameters[12].Value = model.AddPriceState;
            parameters[13].Value = model.AddPrice;
            parameters[14].Value = model.ProductNumberList;
            parameters[15].Value = model.OrderGeneratedTime;
            parameters[16].Value = model.OrderVerifyTime;
            parameters[17].Value = model.VerifyNameId;
            parameters[18].Value = model.AddressId;
            parameters[19].Value = model.UserMessage;
            parameters[20].Value = model.UserIp;
            parameters[21].Value = model.IsPayment;
            parameters[22].Value = model.PaymentTypeId;
            parameters[23].Value = model.PaymentBankId;
            parameters[24].Value = model.PaymentPrice;
            parameters[25].Value = model.PaymentTime;
            parameters[26].Value = model.PaymentOrderNumber;
            parameters[27].Value = model.RefundTypeId;
            parameters[28].Value = model.LogisticsStateId;
            parameters[29].Value = model.Logisticsnumber;
            parameters[30].Value = model.PenskeLogistics;
            parameters[31].Value = model.LogisticsRemarks;
            parameters[32].Value = model.OrderStateCodeId;
            parameters[33].Value = model.ProductOrderNumber;
            parameters[34].Value = model.IsDeliver;
            parameters[35].Value = model.DeliverTime;
            parameters[36].Value = model.DeliverUnitId;
            parameters[37].Value = model.IsPrintDeliver;
            parameters[38].Value = model.AllocateUnitId;
            parameters[39].Value = model.AllocateTime;
            parameters[40].Value = model.AdminMessageId;
            parameters[41].Value = model.IsShow;
            parameters[42].Value = model.Pro_AttrList;

            DbHelperSQL.RunProcedure("Golf_Order_ADD", parameters, out rowsAffected);
            return (int)parameters[0].Value;
        }

        /// <summary>
        ///  更新一条数据
        /// </summary>
        public bool Update(Golf.Model.Golf_Order model)
        {
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4),
					new SqlParameter("@OrderNumber", SqlDbType.NVarChar,15),
					new SqlParameter("@OrderSumPrice", SqlDbType.Decimal,9),
					new SqlParameter("@UserId", SqlDbType.Int,4),
					new SqlParameter("@FristName", SqlDbType.NVarChar,100),
					new SqlParameter("@LastName", SqlDbType.NVarChar,100),
					new SqlParameter("@ProductSumPrice", SqlDbType.Decimal,9),
					new SqlParameter("@TransportationPrice", SqlDbType.Decimal,9),
					new SqlParameter("@MailTypeId", SqlDbType.Int,4),
					new SqlParameter("@IsCoupon", SqlDbType.Bit,1),
					new SqlParameter("@CouponPrice", SqlDbType.Decimal,9),
					new SqlParameter("@IsAddPrice", SqlDbType.Int,4),
					new SqlParameter("@AddPriceState", SqlDbType.NVarChar,200),
					new SqlParameter("@AddPrice", SqlDbType.Decimal,9),
					new SqlParameter("@ProductNumberList", SqlDbType.NVarChar,2000),
					new SqlParameter("@OrderGeneratedTime", SqlDbType.DateTime),
					new SqlParameter("@OrderVerifyTime", SqlDbType.DateTime),
					new SqlParameter("@VerifyNameId", SqlDbType.Int,4),
					new SqlParameter("@AddressId", SqlDbType.Int,4),
					new SqlParameter("@UserMessage", SqlDbType.NVarChar,500),
					new SqlParameter("@UserIp", SqlDbType.NVarChar,15),
					new SqlParameter("@IsPayment", SqlDbType.Int,4),
					new SqlParameter("@PaymentTypeId", SqlDbType.Int,4),
					new SqlParameter("@PaymentBankId", SqlDbType.Int,4),
					new SqlParameter("@PaymentPrice", SqlDbType.Decimal,9),
					new SqlParameter("@PaymentTime", SqlDbType.DateTime),
					new SqlParameter("@PaymentOrderNumber", SqlDbType.NVarChar,50),
					new SqlParameter("@RefundTypeId", SqlDbType.Int,4),
					new SqlParameter("@LogisticsStateId", SqlDbType.Int,4),
					new SqlParameter("@Logisticsnumber", SqlDbType.NVarChar,50),
					new SqlParameter("@PenskeLogistics", SqlDbType.NVarChar,50),
					new SqlParameter("@LogisticsRemarks", SqlDbType.NVarChar,200),
					new SqlParameter("@OrderStateCodeId", SqlDbType.Int,4),
					new SqlParameter("@ProductOrderNumber", SqlDbType.Int,4),
					new SqlParameter("@IsDeliver", SqlDbType.Bit,1),
					new SqlParameter("@DeliverTime", SqlDbType.DateTime),
					new SqlParameter("@DeliverUnitId", SqlDbType.Int,4),
					new SqlParameter("@IsPrintDeliver", SqlDbType.Bit,1),
					new SqlParameter("@AllocateUnitId", SqlDbType.Int,4),
					new SqlParameter("@AllocateTime", SqlDbType.DateTime),
					new SqlParameter("@AdminMessageId", SqlDbType.Int,4),
					new SqlParameter("@IsShow", SqlDbType.Bit,1),
					new SqlParameter("@Pro_AttrList", SqlDbType.NVarChar,2000)};
            parameters[0].Value = model.Id;
            parameters[1].Value = model.OrderNumber;
            parameters[2].Value = model.OrderSumPrice;
            parameters[3].Value = model.UserId;
            parameters[4].Value = model.FristName;
            parameters[5].Value = model.LastName;
            parameters[6].Value = model.ProductSumPrice;
            parameters[7].Value = model.TransportationPrice;
            parameters[8].Value = model.MailTypeId;
            parameters[9].Value = model.IsCoupon;
            parameters[10].Value = model.CouponPrice;
            parameters[11].Value = model.IsAddPrice;
            parameters[12].Value = model.AddPriceState;
            parameters[13].Value = model.AddPrice;
            parameters[14].Value = model.ProductNumberList;
            parameters[15].Value = model.OrderGeneratedTime;
            parameters[16].Value = model.OrderVerifyTime;
            parameters[17].Value = model.VerifyNameId;
            parameters[18].Value = model.AddressId;
            parameters[19].Value = model.UserMessage;
            parameters[20].Value = model.UserIp;
            parameters[21].Value = model.IsPayment;
            parameters[22].Value = model.PaymentTypeId;
            parameters[23].Value = model.PaymentBankId;
            parameters[24].Value = model.PaymentPrice;
            parameters[25].Value = model.PaymentTime;
            parameters[26].Value = model.PaymentOrderNumber;
            parameters[27].Value = model.RefundTypeId;
            parameters[28].Value = model.LogisticsStateId;
            parameters[29].Value = model.Logisticsnumber;
            parameters[30].Value = model.PenskeLogistics;
            parameters[31].Value = model.LogisticsRemarks;
            parameters[32].Value = model.OrderStateCodeId;
            parameters[33].Value = model.ProductOrderNumber;
            parameters[34].Value = model.IsDeliver;
            parameters[35].Value = model.DeliverTime;
            parameters[36].Value = model.DeliverUnitId;
            parameters[37].Value = model.IsPrintDeliver;
            parameters[38].Value = model.AllocateUnitId;
            parameters[39].Value = model.AllocateTime;
            parameters[40].Value = model.AdminMessageId;
            parameters[41].Value = model.IsShow;
            parameters[42].Value = model.Pro_AttrList;

            DbHelperSQL.RunProcedure("Golf_Order_Update", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            DbHelperSQL.RunProcedure("Golf_Order_Delete", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Golf_Order ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Golf.Model.Golf_Order GetModel(int Id)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            Golf.Model.Golf_Order model = new Golf.Model.Golf_Order();
            DataSet ds = DbHelperSQL.RunProcedure("Golf_Order_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderNumber"] != null && ds.Tables[0].Rows[0]["OrderNumber"].ToString() != "")
                {
                    model.OrderNumber = ds.Tables[0].Rows[0]["OrderNumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["OrderSumPrice"] != null && ds.Tables[0].Rows[0]["OrderSumPrice"].ToString() != "")
                {
                    model.OrderSumPrice = decimal.Parse(ds.Tables[0].Rows[0]["OrderSumPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserId"] != null && ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FristName"] != null && ds.Tables[0].Rows[0]["FristName"].ToString() != "")
                {
                    model.FristName = ds.Tables[0].Rows[0]["FristName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LastName"] != null && ds.Tables[0].Rows[0]["LastName"].ToString() != "")
                {
                    model.LastName = ds.Tables[0].Rows[0]["LastName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ProductSumPrice"] != null && ds.Tables[0].Rows[0]["ProductSumPrice"].ToString() != "")
                {
                    model.ProductSumPrice = decimal.Parse(ds.Tables[0].Rows[0]["ProductSumPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TransportationPrice"] != null && ds.Tables[0].Rows[0]["TransportationPrice"].ToString() != "")
                {
                    model.TransportationPrice = decimal.Parse(ds.Tables[0].Rows[0]["TransportationPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MailTypeId"] != null && ds.Tables[0].Rows[0]["MailTypeId"].ToString() != "")
                {
                    model.MailTypeId = int.Parse(ds.Tables[0].Rows[0]["MailTypeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsCoupon"] != null && ds.Tables[0].Rows[0]["IsCoupon"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsCoupon"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsCoupon"].ToString().ToLower() == "true"))
                    {
                        model.IsCoupon = true;
                    }
                    else
                    {
                        model.IsCoupon = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["CouponPrice"] != null && ds.Tables[0].Rows[0]["CouponPrice"].ToString() != "")
                {
                    model.CouponPrice = decimal.Parse(ds.Tables[0].Rows[0]["CouponPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsAddPrice"] != null && ds.Tables[0].Rows[0]["IsAddPrice"].ToString() != "")
                {
                    model.IsAddPrice = int.Parse(ds.Tables[0].Rows[0]["IsAddPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AddPriceState"] != null && ds.Tables[0].Rows[0]["AddPriceState"].ToString() != "")
                {
                    model.AddPriceState = ds.Tables[0].Rows[0]["AddPriceState"].ToString();
                }
                if (ds.Tables[0].Rows[0]["AddPrice"] != null && ds.Tables[0].Rows[0]["AddPrice"].ToString() != "")
                {
                    model.AddPrice = decimal.Parse(ds.Tables[0].Rows[0]["AddPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductNumberList"] != null && ds.Tables[0].Rows[0]["ProductNumberList"].ToString() != "")
                {
                    model.ProductNumberList = ds.Tables[0].Rows[0]["ProductNumberList"].ToString();
                }
                if (ds.Tables[0].Rows[0]["OrderGeneratedTime"] != null && ds.Tables[0].Rows[0]["OrderGeneratedTime"].ToString() != "")
                {
                    model.OrderGeneratedTime = DateTime.Parse(ds.Tables[0].Rows[0]["OrderGeneratedTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderVerifyTime"] != null && ds.Tables[0].Rows[0]["OrderVerifyTime"].ToString() != "")
                {
                    model.OrderVerifyTime = DateTime.Parse(ds.Tables[0].Rows[0]["OrderVerifyTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["VerifyNameId"] != null && ds.Tables[0].Rows[0]["VerifyNameId"].ToString() != "")
                {
                    model.VerifyNameId = int.Parse(ds.Tables[0].Rows[0]["VerifyNameId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AddressId"] != null && ds.Tables[0].Rows[0]["AddressId"].ToString() != "")
                {
                    model.AddressId = int.Parse(ds.Tables[0].Rows[0]["AddressId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserMessage"] != null && ds.Tables[0].Rows[0]["UserMessage"].ToString() != "")
                {
                    model.UserMessage = ds.Tables[0].Rows[0]["UserMessage"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UserIp"] != null && ds.Tables[0].Rows[0]["UserIp"].ToString() != "")
                {
                    model.UserIp = ds.Tables[0].Rows[0]["UserIp"].ToString();
                }
                if (ds.Tables[0].Rows[0]["IsPayment"] != null && ds.Tables[0].Rows[0]["IsPayment"].ToString() != "")
                {
                    model.IsPayment = int.Parse(ds.Tables[0].Rows[0]["IsPayment"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentTypeId"] != null && ds.Tables[0].Rows[0]["PaymentTypeId"].ToString() != "")
                {
                    model.PaymentTypeId = int.Parse(ds.Tables[0].Rows[0]["PaymentTypeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentBankId"] != null && ds.Tables[0].Rows[0]["PaymentBankId"].ToString() != "")
                {
                    model.PaymentBankId = int.Parse(ds.Tables[0].Rows[0]["PaymentBankId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentPrice"] != null && ds.Tables[0].Rows[0]["PaymentPrice"].ToString() != "")
                {
                    model.PaymentPrice = decimal.Parse(ds.Tables[0].Rows[0]["PaymentPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentTime"] != null && ds.Tables[0].Rows[0]["PaymentTime"].ToString() != "")
                {
                    model.PaymentTime = DateTime.Parse(ds.Tables[0].Rows[0]["PaymentTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PaymentOrderNumber"] != null && ds.Tables[0].Rows[0]["PaymentOrderNumber"].ToString() != "")
                {
                    model.PaymentOrderNumber = ds.Tables[0].Rows[0]["PaymentOrderNumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["RefundTypeId"] != null && ds.Tables[0].Rows[0]["RefundTypeId"].ToString() != "")
                {
                    model.RefundTypeId = int.Parse(ds.Tables[0].Rows[0]["RefundTypeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LogisticsStateId"] != null && ds.Tables[0].Rows[0]["LogisticsStateId"].ToString() != "")
                {
                    model.LogisticsStateId = int.Parse(ds.Tables[0].Rows[0]["LogisticsStateId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Logisticsnumber"] != null && ds.Tables[0].Rows[0]["Logisticsnumber"].ToString() != "")
                {
                    model.Logisticsnumber = ds.Tables[0].Rows[0]["Logisticsnumber"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PenskeLogistics"] != null && ds.Tables[0].Rows[0]["PenskeLogistics"].ToString() != "")
                {
                    model.PenskeLogistics = ds.Tables[0].Rows[0]["PenskeLogistics"].ToString();
                }
                if (ds.Tables[0].Rows[0]["LogisticsRemarks"] != null && ds.Tables[0].Rows[0]["LogisticsRemarks"].ToString() != "")
                {
                    model.LogisticsRemarks = ds.Tables[0].Rows[0]["LogisticsRemarks"].ToString();
                }
                if (ds.Tables[0].Rows[0]["OrderStateCodeId"] != null && ds.Tables[0].Rows[0]["OrderStateCodeId"].ToString() != "")
                {
                    model.OrderStateCodeId = int.Parse(ds.Tables[0].Rows[0]["OrderStateCodeId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductOrderNumber"] != null && ds.Tables[0].Rows[0]["ProductOrderNumber"].ToString() != "")
                {
                    model.ProductOrderNumber = int.Parse(ds.Tables[0].Rows[0]["ProductOrderNumber"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsDeliver"] != null && ds.Tables[0].Rows[0]["IsDeliver"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsDeliver"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsDeliver"].ToString().ToLower() == "true"))
                    {
                        model.IsDeliver = true;
                    }
                    else
                    {
                        model.IsDeliver = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["DeliverTime"] != null && ds.Tables[0].Rows[0]["DeliverTime"].ToString() != "")
                {
                    model.DeliverTime = DateTime.Parse(ds.Tables[0].Rows[0]["DeliverTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DeliverUnitId"] != null && ds.Tables[0].Rows[0]["DeliverUnitId"].ToString() != "")
                {
                    model.DeliverUnitId = int.Parse(ds.Tables[0].Rows[0]["DeliverUnitId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsPrintDeliver"] != null && ds.Tables[0].Rows[0]["IsPrintDeliver"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsPrintDeliver"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsPrintDeliver"].ToString().ToLower() == "true"))
                    {
                        model.IsPrintDeliver = true;
                    }
                    else
                    {
                        model.IsPrintDeliver = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["AllocateUnitId"] != null && ds.Tables[0].Rows[0]["AllocateUnitId"].ToString() != "")
                {
                    model.AllocateUnitId = int.Parse(ds.Tables[0].Rows[0]["AllocateUnitId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AllocateTime"] != null && ds.Tables[0].Rows[0]["AllocateTime"].ToString() != "")
                {
                    model.AllocateTime = DateTime.Parse(ds.Tables[0].Rows[0]["AllocateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AdminMessageId"] != null && ds.Tables[0].Rows[0]["AdminMessageId"].ToString() != "")
                {
                    model.AdminMessageId = int.Parse(ds.Tables[0].Rows[0]["AdminMessageId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsShow"] != null && ds.Tables[0].Rows[0]["IsShow"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsShow"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsShow"].ToString().ToLower() == "true"))
                    {
                        model.IsShow = true;
                    }
                    else
                    {
                        model.IsShow = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Pro_AttrList"] != null && ds.Tables[0].Rows[0]["Pro_AttrList"].ToString() != "")
                {
                    model.Pro_AttrList = ds.Tables[0].Rows[0]["Pro_AttrList"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Id,OrderNumber,OrderSumPrice,UserId,FristName,LastName,ProductSumPrice,TransportationPrice,MailTypeId,IsCoupon,CouponPrice,IsAddPrice,AddPriceState,AddPrice,ProductNumberList,OrderGeneratedTime,OrderVerifyTime,VerifyNameId,AddressId,UserMessage,UserIp,IsPayment,PaymentTypeId,PaymentBankId,PaymentPrice,PaymentTime,PaymentOrderNumber,RefundTypeId,LogisticsStateId,Logisticsnumber,PenskeLogistics,LogisticsRemarks,OrderStateCodeId,ProductOrderNumber,IsDeliver,DeliverTime,DeliverUnitId,IsPrintDeliver,AllocateUnitId,AllocateTime,AdminMessageId,IsShow,Pro_AttrList ");
            strSql.Append(" FROM Golf_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,OrderNumber,OrderSumPrice,UserId,FristName,LastName,ProductSumPrice,TransportationPrice,MailTypeId,IsCoupon,CouponPrice,IsAddPrice,AddPriceState,AddPrice,ProductNumberList,OrderGeneratedTime,OrderVerifyTime,VerifyNameId,AddressId,UserMessage,UserIp,IsPayment,PaymentTypeId,PaymentBankId,PaymentPrice,PaymentTime,PaymentOrderNumber,RefundTypeId,LogisticsStateId,Logisticsnumber,PenskeLogistics,LogisticsRemarks,OrderStateCodeId,ProductOrderNumber,IsDeliver,DeliverTime,DeliverUnitId,IsPrintDeliver,AllocateUnitId,AllocateTime,AdminMessageId,IsShow,Pro_AttrList ");
            strSql.Append(" FROM Golf_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Golf_Order ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Golf_Order T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
            parameters[0].Value = "Golf_Order";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 1;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
        }

        #endregion  Method
    }
}

